package org.nlp2rdf.navigator.benchmark.cli;

import com.hp.hpl.jena.rdf.model.Resource;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.nlp2rdf.navigator.benchmark.BenchmarkContext;
import org.nlp2rdf.navigator.benchmark.BenchmarkUtils;
import org.nlp2rdf.navigator.benchmark.PoolUtils;
import org.nlp2rdf.navigator.benchmark.Sample;
import org.springframework.context.ApplicationContext;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Created by Claus Stadler
 * Date: Oct 23, 2010
 * Time: 11:07:46 AM
 */
public class RunPoolSearch {

    private static Options cliOptions = new Options()
        .addOption("f", "sampleFile", true, "File containing a list of positive resources")
        .addOption("c", "configFile", true, "Spring XML config")
        .addOption("k", "keyword", true, "Keyword to search for");

    public static void main(String[] args)
            throws Exception
    {
        CommandLine commandLine = CliUtils.getGnuCommandLine(cliOptions, args);
        ApplicationContext context = CliUtils.getApplicationContext(commandLine, commandLine.getOptionValue("c"));

        BenchmarkContext con = new BenchmarkContext(context);

        String keywords = commandLine.getOptionValue("k");

        List<Resource> resources = BenchmarkUtils.readResources(commandLine.getOptionValue("f"));
        Set<Resource> positives = new HashSet<Resource>(resources);

        Sample<Resource> sample = PoolUtils.generateKeywordSearchPool(con.getSparqlEndpoint(), con.getGraphNames(), keywords, positives);

        CliUtils.outputSample(sample);
    }
}
